package com.yulongtian.oneProblemEveryDay.month202212;

/**
 * @author yulongTian
 * @create 2022-12-15 11:24
 */
public class Test09 {
    public static void main(String[] args) {

    }


    int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8};

    public int getLucky(String s, int k) {

        int temp = 0;
        for (int i = 0; i < s.length(); i++) {
            temp += nums[s.charAt(i) - 'a'];
        }

        if (k == 1) {
            return temp;
        }
        int res = 0;

        while (k > 1) {

            while (temp > 0) {
                res += temp % 10;
                temp /= 10;
            }
            temp = res;
            if (k - 1 > 1) {
                res = 0;
            }
            k--;
        }
        return res;
    }
}
